package day_2022_7_to_8.day48;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author haomin
 * @date 2022/08/17 15:07
 **/
public class Day32_1_Num1302_DeepestLeavesSum {
    class Solution {
        public int deepestLeavesSum(TreeNode root) {
            if(root == null) return 0;
            Queue<TreeNode> queue = new LinkedList();
            queue.offer(root);
            int res = 0;
            while(!queue.isEmpty()){
                int size = queue.size();
                int sum = 0;
                for(int i = 0;i < size;i++){
                    TreeNode cur = queue.poll();sum+=cur.val;
                    if(cur.left != null) queue.offer(cur.left);
                    if(cur.right != null) queue.offer(cur.right);
                }
                res = sum;
            }
            return res;
        }
    }
}